﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace nSin.TaskSwitcher
{
    /// <summary>
    /// Interaction logic for TaskSwitcherControl.xaml
    /// </summary>
    public partial class TaskSwitcherControl : UserControl
    {
        private TabControl _objTabControl;
        private ObservableCollection<TabItemMetaData> _objTabItems; 

        public TaskSwitcherControl()
        {
            InitializeComponent();
        }
        internal void Show(TabControl objTabControl)
        {
            _objTabControl = objTabControl;

            if (objTabControl.Items.Count < 1)
            {
                Hide();
                return;
            }

            _objTabItems = new ObservableCollection<TabItemMetaData>();

            for (int intX = 0; intX <= objTabControl.Items.Count - 1; intX++)
            {

                TabItem obj = (TabItem)objTabControl.Items[intX];
                TabItemMetaData objTabItemMetaData = (TabItemMetaData)obj.Tag;
                objTabItemMetaData.TabControlIndex = intX;
                _objTabItems.Add(objTabItemMetaData);
            }

            this.lbFormList.DataContext = _objTabItems;
            this.UpdateLayout();
            this.lbFormList.SelectedIndex = objTabControl.SelectedIndex;

            this.lbFormList.Focus();

        }

        internal void Hide()
        {
            _objTabControl.SelectedIndex = ((TabItemMetaData)((TabItem)_objTabControl.Items[this.lbFormList.SelectedIndex]).Tag).TabControlIndex;
            this.Visibility = System.Windows.Visibility.Collapsed;
            _objTabItems = null;
            this.lbFormList.DataContext = null;

        } 

    }
}
